<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/3/8
 * Time: 下午4:00
 */
use common\models\MobileCoupon;
use kartik\datetime\DateTimePicker;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\MobileChannel;

?>
<?php
$category = \common\models\CouponCategory::find()->select('id,group_id,name')->asArray()->all();
$categoryList = [];
if (count($category) > 0) {
    foreach ($category as $v) {
        $categoryList[$v['id']] = $v['name'];
    }
}
?>
<div class="article-index">
    <?php $form = ActiveForm::begin([
        'method' => 'get',

    ]); ?>

    <?= $form->field($model, 'phone')->textInput()->label("手机号") ?>
    <?= $form->field($model, 'status')->dropDownList(['' => '全部'] + \common\models\BindPhone::getStatusList())->label("状态") ?>
    <?= $form->field($model, 'startTime')->widget(DateTimePicker::classname(),
        ['options' => ['placeholder' => '开始时间'],
            'pluginOptions' => [
                'autoclose' => true,
                'todayHighlight' => true,
                'format' => 'yyyy-mm-dd hh:ii:ss',
                'inline' => true,
            ]
        ])->label("开始时间");
    ?>

    <?= $form->field($model, 'endTime')->widget(DateTimePicker::classname(),
        ['options' => ['placeholder' => '开始时间'],
            'pluginOptions' => [
                'autoclose' => true,
                'todayHighlight' => true,
                'format' => 'yyyy-mm-dd hh:ii:ss',
                'inline' => true,
            ]
        ])->label("结束时间");
    ?>

    <div id="search-option">
        <?= Html::submitButton('搜索', ['class' => 'btn btn-primary center']) ?>
    </div>
    <?php ActiveForm::end(); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'phone',
            'coupon_id',
            [
                'attribute' => 'created_at',
                'value' => function ($model) {
                    return date("Y-m-d H:i:s", $model->created_at);
                }
            ],
            [
                'attribute' => 'updated_at',
                'value' => function ($model) {
                    return date("Y-m-d H:i:s", $model->updated_at);
                }
            ],
            'msg',
            'attempt',
            [
                'attribute' => 'status',
                'value' => function ($model) {
                    return \common\models\BindPhone::getStatusList()[$model->status];
                }
            ],
            ['class' => 'yii\grid\ActionColumn',
                'template' => '{execute}',
                'buttons' => [
                    'execute' => function ($url, $model, $key) {
                        return Html::a('执行', \yii\helpers\Url::to(['execute', 'id' => $model->id]));
                    },
                ],
            ],
        ],
    ]); ?>
</div>